package com.shine.rabbitmq.sender;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.shine.rabbitmq.constant.RabbitConstant;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @author huihui
 * @date 2025/5/7 14:06
 * @description MessageSender
 */
@Slf4j
@Component
public class MessageSender {

    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送Obj数据，自动转JSON
     *
     * @param exchange
     * @param routeingKey
     * @param dataJson
     */
    public void send(String exchange, String routeingKey, Object dataJson) {
        rabbitTemplate.convertAndSend(exchange, routeingKey, dataJson);
    }

    /**
     * 发送JSON数据
     *
     * @param exchange
     * @param routeingKey
     * @param dataJson
     */
    public void send(String exchange, String routeingKey, String dataJson) {
        rabbitTemplate.convertAndSend(exchange, routeingKey, dataJson);
    }

    /**
     * 发送ID
     *
     * @param exchange
     * @param routeingKey
     * @param dataId
     */
    public void send(String exchange, String routeingKey, Long dataId) {
        rabbitTemplate.convertAndSend(exchange, routeingKey, dataId);
    }

}
